package com.xinguan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinguan.entity.Advertisement;
import com.xinguan.mapper.AdvertisementMapper;
import com.xinguan.service.AdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 陈俊行
 * @Date: 2023/11/08/17:30
 * @Description:
 */
@Service
public class AdvertisementServiceImpl extends ServiceImpl<AdvertisementMapper, Advertisement> implements AdvertisementService {
    @Autowired
    private AdvertisementMapper advertisementMapper;

    @Override
    public void increaseAdvertisement(Advertisement advertisement) {
        Advertisement advertisement1=new Advertisement();
        advertisement1.setAdCompany(advertisement.getAdCompany());
        advertisement1.setAdName(advertisement.getAdName());
        advertisement1.setAdCategory(advertisement.getAdCategory());
        advertisement1.setFile(advertisement.getFile());
        advertisementMapper.insert(advertisement1);
    }

    @Override
    public void updatePhoto(Advertisement advertisement) {
        LambdaQueryWrapper<Advertisement> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Advertisement::getAdName,advertisement.getAdName());
        Advertisement advertisement1 = advertisementMapper.selectOne(wrapper);
        System.out.println(advertisement1);
        advertisement1.setFile(advertisement.getFile());
        advertisementMapper.updateById(advertisement1);
    }

    @Override
    public List<Advertisement> getAllAdvertisement() {
        LambdaQueryWrapper<Advertisement> wrapper=new LambdaQueryWrapper<>();
        List<Advertisement> advertisements = advertisementMapper.selectList(wrapper);
        return  advertisements;
    }

    @Override
    public void deleteAdvertisement(Advertisement advertisement) {
        LambdaQueryWrapper<Advertisement> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Advertisement::getAdName,advertisement.getAdName());
        Advertisement advertisement1 = advertisementMapper.selectOne(wrapper);
        advertisementMapper.deleteById(advertisement1);

    }
}
